package com.sxkiler.demo.seata.controller;

import com.sxkiler.demo.seata.dto.OrderDTO;
import com.sxkiler.demo.seata.service.at.ATOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order/at")
public class ATOrderController {

    private final Logger logger = LoggerFactory.getLogger(ATOrderController.class);

    @Autowired
    private ATOrderService orderService;

    @PostMapping("/create-order")
    public boolean createOrder(@RequestBody OrderDTO orderDTO) throws Exception {
        logger.info("[createOrder] 收到下单请求, 用户:{}, 商品:{}, 数量:{}", orderDTO.getUserId(), orderDTO.getProductId(), orderDTO.getCount());
        return orderService.createOrder(orderDTO);
    }

}
